import { LoadingBar } from 'quasar'
import InterfaceProxy from 'src/utils/mider'
import { defaultOptions, ResponseData } from './_options'

/**
 * 工具
 * @namespace iTool
 */

/** @lends iTool# */
const interfaceOpt = {
  getToolByIds: {
    url: '/p/v1/tool-api/tool/actions/getByIds',
    method: 'post',
    data: {
      ids: Array
    }
  },
  findToolsByTagId: {
    url: 'p/v1/tool-api/:id/list',
    method: 'get',
    pathParams: {
      id: String
    }
  },
  findTools: {
    url: 'p/v1/tool-api/tools',
    method: 'get',
    params: {
      tags: Array,
      keywords: String,
      ids: Array,
      sorts: String
    },
    beforeSend () {
      LoadingBar.start()
    },
    successHandler (res: ResponseData) {
      LoadingBar.stop()
      return {
        success: res.code === 0,
        data: res.data,
        msg: res.msg
      }
    }
  },
  findAllTags: {
    url: '/p/v1/tool-api/tags',
    method: 'get',
    validTime: 60
  },
  getSiteInfo: {
    url: '/p/v1/tool-api/tool/actions/getSiteInfo',
    method: 'post',
    params: {
      query: {
        url: String
      }
    }
  },
  findAllTopic: {
    url: '/p/v1/tool-api/topic/actions/findAll',
    method: 'post',
    params: {
      query: {
        status: Number
      }
    }
  }
}

/** @mixes iTool */
const iTool = new InterfaceProxy(interfaceOpt, [defaultOptions])
export default iTool
